#ifndef __MUTEX_H__
#define __MUTEX_H__

#include <pthread.h>
#include <iostream>

class Mutex {
private:
	pthread_mutex_t m;
	Mutex(const Mutex &c) {
	}
	;
public:
	Mutex() {
		pthread_mutex_init(&m, 0);
	}
	~Mutex() {
		pthread_mutex_destroy(&m);
	}
	void lock() {
		pthread_mutex_lock(&m);
	}
	void unlock() {
		pthread_mutex_unlock(&m);
	}
	friend class Lock;
};

class Lock {
private:
	Mutex &m;
	Lock(const Lock &c) :
			m(c.m) {
	}
	;
public:
	Lock(Mutex &m) :
			m(m) {
		m.lock();
	}
	~Lock() {
		m.unlock();
	}
};

#endif
